package com.fanhang.samples.spring.jdbc.dao.impl;

import java.util.List;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcDaoSupport;
import org.springframework.stereotype.Repository;

import com.fanhang.samples.spring.jdbc.dao.UserDao;
import com.fanhang.samples.spring.jdbc.po.User;

@Repository
public class UserDaoImpl extends NamedParameterJdbcDaoSupport implements UserDao {

	@Override
	public User get(Long id) {
		String sql = "SELECT * FROM stat_user WHERE id = ?";
		// return super.get(sql, new Long[]{id});
		return super.getJdbcTemplate().queryForObject(sql,
				new BeanPropertyRowMapper<User>(User.class), id);
	}
	

	@Override
	public List<User> getList(User model) {
		// StringBuilder sql = new
		// StringBuilder("SELECT * FROM stat_user WHERE 1=1 ");
		// if (model.getRoleId() != null) {
		// sql.append(" and role_id = :roleId ");
		// }
		// if (model.getCreator() != null) {
		// sql.append(" and creator = :creator ");
		// }
		// if (!StringUtils.isEmpty(model.getUserName())) {
		// sql.append(" and user_name like '%:userName%' ");
		// }
		// return super.getList(sql.toString(), model, User.class);
		return null;
	}
	

	@Override
	public int save(User model) {
		// String sql =
		// "insert into stat_user(id,login_name,password,user_name,role_id,status,creator,create_time) values (:id, :loginName, :password, :userName, :roleId, :status, :creator, :createTime)";
		// return super.update(sql, model);
		return 0;
	}

	@Override
	public int delete(User model) {
		// String sql =
		// "update employee set name=:name,birthday=:birthday,status=:status WHERE id = :id";
		// return super.update(sql, new BeanPropertySqlParameterSource(model));
		return 0;
	}

	@Override
	public int update(User model) {
		// String sql =
		// "update employee set name=:name,birthday=:birthday,status=:status WHERE id = :id";
		// return super.update(sql, new BeanPropertySqlParameterSource(model));
		return 0;
	}
}
